import { LOGIN_TOKEN } from '@/constants'
import { localCache } from '@/utils/cache'
import Layout from '@/layouts/index.vue'
import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [{
        path: '/',
        redirect: '/Index'
    },
    {
        name: 'login',
        path: '/Login',
        meta: {
            title: '登录'
        },
        component: () =>
            import ('@/pages/Login/Index.vue')
    },
    {
        name: 'createScheme',
        path: '/CreateScheme',
        meta: {
            title: '新建预报'
        },
        component: () =>
            import ('@/pages/embeddedPage/createScheme/index.vue')
    },
    {
        path: '/model',
        component: Layout,
        redirect: 'noRedirect',
        name: 'Model',
        meta: { title: '模型', icon: 'box-open' },
        children: [{
                name: 'index',
                path: '/Index',
                meta: {
                    title: '首页'
                },
                component: () =>
                    import ('@/pages/Home/Index.vue'),

            },
            {
                name: 'model',
                path: '/Model',
                meta: {
                    title: '模型管理'
                },
                component: () =>
                    import ('@/pages/ModelManage/Index.vue')
            },
            {
                name: 'computeMethods',
                path: '/ComputeMethods',
                meta: {
                    title: '计算方案'
                },
                component: () =>
                    import ('@/pages/ComputeMethods/Index.vue')
            },
            {
                name: 'dispatchManage',
                path: '/DispatchManage',
                meta: {
                    title: '调度管理'
                },
                component: () =>
                    import ('@/pages/DispatchManage/Index.vue')
            },
            {
                name: 'modelExam',
                path: '/ModelExam',
                meta: {
                    title: '模型考核'
                },
                component: () =>
                    import ('@/pages/ModelExam/Index.vue')
            },
            {
                name: 'externalService',
                path: '/ExternalService',
                meta: {
                    title: '对外服务'
                },
                component: () =>
                    import ('@/pages/ExternalService/Index.vue')
            }
        ]
    },


]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to) => {
    document.title = `${to.meta.title} | 模型管理平台`

    // const token = localCache.getCache(LOGIN_TOKEN)
    // if (!token && to.path !== '/login') {
    //   return '/login'
    // }
})

export default router
